#ifndef CLIENT_INFO_H
#define CLIENT_INFO_H

#include <cstdint>
#include <vector>
#include <map>
#include "mdfu.h"

class ClientInfo {
public:
    // 构造函数
    ClientInfo(uint8_t major, uint8_t minor, uint8_t patch, uint8_t alpha, bool alphaValid, uint8_t bufferCount, uint16_t bufferSize, 
               float defaultTimeout, const std::map<MdfuCmd, float>& timeouts = {}, float interTransactionDelay = 0.0f);
    
    // 将 ClientInfo 转换为字节流
    std::vector<uint8_t> toBytes() const;
    
    // 解析字节流，返回 ClientInfo 对象
    static ClientInfo fromBytes(const std::vector<uint8_t>& data);
    
    // 获取 MDFU 版本
    std::string getProtocolVersion() const;
    
    // 获取缓冲区信息
    uint16_t getBufferSize() const;
    uint8_t getBufferCount() const;
    
    // 获取超时时间
    float getDefaultTimeout() const;
    float getCommandTimeout(MdfuCmd cmd) const;
    
    // 获取事务间延迟
    float getInterTransactionDelay() const;
    
private:
    
    static constexpr uint8_t PARAM_TYPE_SIZE = 1;
    static constexpr uint8_t PARAM_LENGTH_SIZE = 1;
    static constexpr uint8_t BUFFER_INFO_SIZE = 3;
    static constexpr uint8_t PROTOCOL_VERSION_SIZE = 3;
    static constexpr uint8_t PROTOCOL_VERSION_INTERNAL_SIZE = 4;
    static constexpr uint8_t COMMAND_TIMEOUT_SIZE = 3;
    static constexpr uint8_t INTER_TRANSACTION_DELAY_SIZE = 4;
    static constexpr float SECONDS_PER_LSB = 0.1f;
    static constexpr uint8_t LSBS_PER_SECOND = 10;

    uint8_t protocolMajor;
    uint8_t protocolMinor;
    uint8_t protocolPatch;
    uint8_t protocolAlpha;
    bool protocolAlphaValid;
    uint8_t bufferCount;
    uint16_t bufferSize;
    float defaultTimeout;
    std::map<MdfuCmd, float> timeouts;
    float interTransactionDelay;
};

#endif // CLIENT_INFO_H
